from query_analyse.base_query_analyse import BaseQueryAnalyse
from tool.string_tool import remove_punctuation


class SimWord(BaseQueryAnalyse):
    def __init__(self, config):
        super().__init__(config)

    def process_query(self, global_resource, request_content, response_content):
        """
        调用es,获取重要term 的所有近义词
        :return: 
        """
        # 获取term weight 和 term 近义词
        es_service = global_resource.resource_manager.get_service("es_client")
        body = {"query": {"terms": {"word": []}}}
        for term in request_content.get_value("terms"):
            body["query"]["terms"]["word"].append(term)
        data_list = es_service.post_query("sim_word", "sim_word", body)
        word_info = {}
        for data in data_list:
            word_info[data["word"]] = data
        request_content.store_value("word_info", word_info)
